package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageBoardZal;
import cn.wolfcode.domain.MessageReplyZal;
import cn.wolfcode.service.IMessageBoardZalService;
import cn.wolfcode.service.IMessageReplyZalService;
import cn.wolfcode.util.RequestPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/messageReplyZal")
public class MessageReplyZalController {

    @Autowired
    private IMessageReplyZalService messageReplyZalService;
    @Autowired
    private IMessageBoardZalService messageBoardZalService;



    @RequestPermission(name="留言回复页面",expression="messageReplyZal:list")
    @RequestMapping("/list")
    public String list(Model model, Long messageBoardZalId){
        List<MessageReplyZal> list = messageReplyZalService.selectByMessageReplyId(messageBoardZalId);
        int a = 0;
        for (MessageReplyZal m:list){
            a = a+1;
        }
        MessageBoardZal messageBoard = messageBoardZalService.get(messageBoardZalId);
        model.addAttribute("messageBoardZal",messageBoard);
        model.addAttribute("messageReplyZal",list);
        model.addAttribute("num",a);
        return "messageReplyZal/list";
    }



    @RequestPermission(name="留言回复新增/编辑",expression="messageReplyZal:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageReplyZal messageReplyZal) {
        if (messageReplyZal.getId() == null) {
            messageReplyZalService.save(messageReplyZal);
        } else {
            messageReplyZalService.update(messageReplyZal);
        }
        return "redirect:/messageReplyZal/list";
    }



}
